package com.wenwu.service.impl;

import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wenwu.common.bean.Function;
import com.wenwu.common.exception.RelicsException;
import com.wenwu.dao.FunctionMapper;
import com.wenwu.service.FunctionService;

/**
 * @project ATHome-Manager-Service
 * @class FunctionServiceImpl.java
 * @author zhujiagui E-mail:<zhujiagui@zkingsoft.com>
 * @date 2015年3月3日 下午4:30:31
 * @description function模块service层实现类
 */
@Service
public class FunctionServiceImpl implements FunctionService {
	@Autowired
	private FunctionMapper functionMapper;

	public List<Function> selectList() throws RelicsException {
		try {
			return functionMapper.selectByExample(null);
		} catch (Exception e) {
			throw new RelicsException("系统异常");
		}
	}

	public int veriKey(String code) throws RelicsException{
		try {
			return functionMapper.veriKey(code);
		} catch (Exception e) {
			throw new RelicsException("系统异常");
		}
	}

	public int addFunction(Function function) throws RelicsException {
		try {
			return functionMapper.insertSelective(function);
		} catch (Exception e) {
			throw new RelicsException("系统异常");
		}
	}

	public int updateFunction(Function function) throws RelicsException {
		try {
			return functionMapper.updateByPrimaryKey(function);
		} catch (Exception e) {
			throw new RelicsException("系统异常");
		}
	}

	public Function selectByKey(Integer functionId) throws RelicsException {
		try {
			return functionMapper.selectByPrimaryKey(functionId);
		} catch (Exception e) {
			throw new RelicsException("系统异常");
		}
	}

	public int deleteFunctionByKey(List<?> list) throws RelicsException {
		try {
			return functionMapper.deleteFunctionByKey(list);
		} catch (SQLException e) {
			throw new RelicsException("系统错误，请稍后再试", e);
		}
	}
}
